﻿@model PaymentHelper.Core.RelatedObject.Address
@using PaymentHelper.PaymentFlowTemplates.Default.Models;

@{
    ViewBag.Title = ViewBag.Resources["DefaultPaymentFlow.OrderInfoTitle"];

    if (!string.IsNullOrEmpty(PaymentHelper.PaymentFlow.PaymentFlowManager.Layout))
    {
        Layout = PaymentHelper.PaymentFlow.PaymentFlowManager.Layout;
    }
}

<div class="@ViewBag.CssClass">
    
    @Html.Action("PaymentSteps", "DefaultTemplate", new { step = PaymentStep.AddressInfo })

    @using (Html.BeginForm("OrderInfo", "DefaultTemplate", FormMethod.Post, new {  onsubmit = "return checkInput()"}))
    {
        <div class="payment_content">
            @Html.ValidationSummary()
            <fieldset>
                <legend>@ViewBag.Resources["DefaultPaymentFlow.BillingAddress"]</legend>
                <table>
                    <tbody>
                        <tr>
                            <td class='label'>
                                @ViewBag.Resources["DefaultPaymentFlow.FirstName"]
                            </td>
                            <td class='value'>
                                @Html.TextBoxFor(m => m.FirstName)
                            </td>
                        </tr>
                        <tr>
                            <td class='label'>
                                @ViewBag.Resources["DefaultPaymentFlow.LastName"]
                            </td>
                            <td class='value'>
                                @Html.TextBoxFor(m => m.LastName)
                            </td>
                        </tr>
                        <tr>
                            <td class='label'>
                                @ViewBag.Resources["DefaultPaymentFlow.Address"]
                            </td>
                            <td class='value'>
                                @Html.TextBoxFor(m => m.Address1)
                            </td>
                        </tr>
                        <tr>
                            <td class='label'>
                                @ViewBag.Resources["DefaultPaymentFlow.Country"]
                            </td>
                            <td class='value'>
                                @Html.TextBoxFor(m => m.Country)
                            </td>
                        </tr>
                        <tr>
                            <td class='label'>
                                @ViewBag.Resources["DefaultPaymentFlow.City"]
                            </td>
                            <td class='value'>
                                @Html.TextBoxFor(m => m.City)
                            </td>
                        </tr>
                        <tr>
                            <td class='label'>
                                @ViewBag.Resources["DefaultPaymentFlow.ZipCode"]
                            </td>
                            <td class='value'>
                                @Html.TextBoxFor(m => m.ZipPostalCode)
                            </td>
                        </tr>
                        <tr>
                            <td class='label'>
                                @ViewBag.Resources["DefaultPaymentFlow.Fone"]
                            </td>
                            <td class='value'>
                                @Html.TextBoxFor(m => m.PhoneNumber)
                            </td>
                        </tr>
                        <tr>
                            <td class='label'>
                                @ViewBag.Resources["DefaultPaymentFlow.Email"]
                            </td>
                            <td class='value'>
                                @Html.TextBoxFor(m => m.Email)
                            </td>
                        </tr>
                    </tbody>
                </table>
                @if (ViewBag.GetShippingInfo)
                {
                    <input type="button" style="margin: 10px 0px 10px 150px; border: none; padding: 5px;
                    font-weight: bold; cursor: pointer;" value="@ViewBag.Resources["DefaultPaymentFlow.ShipToThis"]" onclick="copyInfo()" />
                }
            </fieldset>
            @if (ViewBag.GetShippingInfo)
            {
            <fieldset>
                <legend>@ViewBag.Resources["DefaultPaymentFlow.ShippingAddress"]</legend>
                <table>
                    <tbody>
                        <tr>
                            <td class='label'>
                                @ViewBag.Resources["DefaultPaymentFlow.FirstName"]
                            </td>
                            <td class='value'>
                                <input type="hidden" id="getshipping" value="1" />
                                <input type="text" name="ship-first-name" id="ship-first-name" />
                            </td>
                        </tr>
                        <tr>
                            <td class='label'>
                                @ViewBag.Resources["DefaultPaymentFlow.LastName"]
                            </td>
                            <td class='value'>
                                <input type="text" name="ship-last-name" id="ship-last-name" />
                            </td>
                        </tr>
                        <tr>
                            <td class='label'>
                                @ViewBag.Resources["DefaultPaymentFlow.Email"]
                            </td>
                            <td class='value'>
                                <input type="text" name="ship-email" id="ship-email" />
                            </td>
                        </tr>
                        <tr>
                            <td class='label'>
                                @ViewBag.Resources["DefaultPaymentFlow.Fone"]
                            </td>
                            <td class='value'>
                                <input type="text" name="ship-fone" id="ship-fone" />
                            </td>
                        </tr>
                        <tr>
                            <td class='label'>
                                @ViewBag.Resources["DefaultPaymentFlow.Country"]
                            </td>
                            <td class='value'>
                                <input type="text" name="ship-country" id="ship-country" />
                            </td>
                        </tr>
                        <tr>
                            <td class='label'>
                                @ViewBag.Resources["DefaultPaymentFlow.City"]
                            </td>
                            <td class='value'>
                                <input type="text" name="ship-city" id="ship-city" />
                            </td>
                        </tr>
                        <tr>
                            <td class='label'>
                                @ViewBag.Resources["DefaultPaymentFlow.ZipCode"]
                            </td>
                            <td class='value'>
                                <input type="text" name="ship-zipcode" id="ship-zipcode" />
                            </td>
                        </tr>
                        <tr>
                            <td class='label'>
                                @ViewBag.Resources["DefaultPaymentFlow.Address"]
                            </td>
                            <td class='value'>
                                <input type="text" name="ship-address1" id="ship-address1" />
                            </td>
                        </tr>
                    </tbody>
                </table>
            </fieldset>
            }
        
        @if (ViewBag.ShowCart)
        {
            @Html.Action("ShowCart", "DefaultTemplate");
        }
        
        </div>            
        <div class="btn_control">
            <p style="text-align: center;">
                <input type="button" value="@ViewBag.Resources["DefaultPaymentFlow.Cancle"]" onclick="location.href='@Url.RouteUrl("DefaultTemplate.Cancle")'" class="btn_ph_payment"/>
                <input type="submit" name="ph_nextstep" value="@ViewBag.Resources["DefaultPaymentFlow.NextStep"]" class="btn_ph_payment"/>
            </p>
        </div>
    }
</div>
@if (ViewBag.GetShippingInfo)
{
    <script type="text/javascript">
        function copyInfo() {
            $('#ship-first-name').val($('#FirstName').val());
            $('#ship-last-name').val($('#LastName').val());
            $('#ship-fone').val($('#PhoneNumber').val());
            $('#ship-address1').val($('#Address1').val());
            $('#ship-city').val($('#City').val());
            $('#ship-country').val($('#Country').val());
            $('#ship-email').val($('#Email').val());
            $('#ship-zipcode').val($('#ZipPostalCode').val());
        }

        function checkInput() {

            if (checkInfoItem('FirstName') == false)
                return false;
            if (checkInfoItem('LastName') == false)
                return false;

            if (checkInfoItem('PhoneNumber') == false)
                return false;

            if (checkInfoItem('Address1') == false)
                return false;

            if (checkInfoItem('City') == false)
                return false;

            if (checkInfoItem('Email') == false)
                return false;

            if ($('#getshipping').val() == '1') {
                
                if (checkInfoItem('ship-first-name') == false)
                    return false;

                if (checkInfoItem('ship-last-name') == false)
                    return false;

                if (checkInfoItem('ship-fone') == false)
                    return false;

                if (checkInfoItem('ship-address1') == false)
                    return false;

                if (checkInfoItem('ship-city') == false)
                    return false;

                if (checkInfoItem('ship-email') == false)
                    return false;
            }

            return true;
        }


        function checkInfoItem(id) {

            var info = $('#' + id);

            if (info.val().trim().length <= 0) {
                info.css('border', '1px solid red');
                return false;
            } else {
                info.css('border', '1px solid #b4b4b4');
                return true;
            }
        }
    </script>
}
